import geekIcon from '@/components/geek-icon.vue'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn'
import hljs from 'highlight.js'
import 'highlight.js/styles/vs2015.css'
dayjs.extend(relativeTime)
dayjs.locale('zh-cn')

export default {
  install: (Vue) => {
    Vue.component(geekIcon.name, geekIcon)
    // 全局注册过滤器
    Vue.filter('relativeTime', (value) => {
      return dayjs(value).toNow()
    })
    // 定义组件代码高亮
    Vue.directive('highlight', (el) => {
      const codeList = el.querySelectorAll('pre code')
      codeList.forEach((code) => {
        hljs.highlightElement(code)
      })
    })
  }
}
